$(function(){
    var htmlNav = "",
        htmlProduct = "";
    var bool = false;
    $.ajax({
        url:"http://chst.vip:1234/api/getindexmenu",
        type: "Get",
        success(res){
            res.result.forEach((item , index) =>{
                var aHerf = item.titlehref;
                var arr = item.img.split('"');
                arr[1] = "../assets/" + arr[1];
                arr = arr.join('"');
                var indexclass = "menu" + item.indexmenuId;
                if(index === 7){
                    aHerf = "#"
                }
                htmlNav +=`
                <div class=${indexclass}>
                    <a href=${aHerf}>
                        ${arr}
                        <p>${item.name}</p>
                    </a>
                </div>
            `
            })
            $("nav").html(htmlNav);
            console.log($("nav"));
            $(".menu7").click(function () {
                if(bool){
                    bool = !bool;
                    $("nav").css({ 
                        height: "5.536rem"
                    })
                } else {
                    bool = !bool;
                    $("nav").css({
                        height: "8.304rem"
                    })
                }
            })
        }
    })

    $.ajax({
        url:"http://chst.vip:1234/api/getmoneyctrl",
        type:"Get",
        success(res){
            console.log(res);
            res.result.forEach(item =>{
                htmlProduct +=`
                <div class="product-item" id=${item.productId}>
                ${item.productImgSm}
                <p class="top">${item.productName}<span>${item.productPinkage}</span></p>
                <p class="bottom"><span>${item.productFrom}|${item.productTime}</span>
                <span>图标${item.productComCount}</span></p>
                </div>
                `
            })
            $("main").html(htmlProduct);
            $("main").on("click",".product-item",function(){
                let productid = $(this).attr("id")
                location.href = `./indexXiang.html?productid=${productid}`
            })
        }
    })
})